package com.dotools.privacy;


import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.dotools.procommon.R;
import com.dotools.umlibrary.UMPostUtils;


public class UnJoinDialog {
    private AlertDialog mDialog = null;
    private UnJoin mClickListener = null;

   public interface UnJoin {
        void onOkClick();
        void onUnOKClick();
    }

    public UnJoinDialog(final Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Privacy_Dialog_Style);
        View view = LayoutInflater.from(context).inflate(R.layout.no_join_dialog, null, false);
        TextView ok = view.findViewById(R.id.user_privacy_ok);
        TextView none = view.findViewById(R.id.user_privacy_none);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogDismiss();
                if (mClickListener != null) {
                    mClickListener.onOkClick();
                }
            }
        });
        none.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 dialogDismiss();
                if (mClickListener != null) {
                    mClickListener.onUnOKClick();
                }
                UMPostUtils.INSTANCE.onEvent(context,"disagree_again_click");
                UMPostUtils.INSTANCE.onKillProcess(context.getApplicationContext());
                System.exit(0);
            }
        });
        mDialog = builder.setView(view).create();
        mDialog.setCanceledOnTouchOutside(false);//点击屏幕不消失
        // 设置参数
        WindowManager.LayoutParams params = mDialog.getWindow().getAttributes();
        // 宽度和高度
        params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.CENTER;
        mDialog.getWindow().setAttributes(params);
        mDialog.show();
    }

    public void setOkClick(UnJoin clickListener) {
        this.mClickListener = clickListener;
    }

    public void dialogDismiss() {
        if (mDialog != null) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
                mDialog = null;
            }
        }
    }
}

